package org.lc.service.system.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.lc.platform.mybatis.entity.BaseEntity;
import org.lc.platform.mybatis.manager.annotation.*;

import java.io.Serial;
import java.io.Serializable;
import java.util.List;

/**
 * sys_menu
 */
@EqualsAndHashCode(callSuper = true)
@Data
@TableName(autoResultMap = true)
@ToString(callSuper = true)
@OrderBy(params = {
        @Params(field = "sort", isAsc = true)
})
public class SysDepartment extends BaseEntity implements Serializable {

    /**
     * 名称
     */
    private String title;
    /**
     * 图标
     */
    private String icon;
    /**
     * 是否叶子菜单
     */
    private Boolean isLeaf;
    /**
     * 序号
     */
    private Integer sort;
    /**
     * 是否禁用部门
     */
    private Boolean forbidden;
    /**
     * 备注
     */
    private String remark;
    /**
     * 主键编码
     */
    @TreeParent
    private String parentId;

    /**
     * 是否含有孩子
     */
    @TableField(exist = false)
    private Boolean hasChildren = true;

    @ManyToOne(selfField = "parentId", target = SysDepartment.class)
    @TableField(exist = false)
    private Parent parent;

    @TreeChildren
    @TableField(exist = false)
    private List<SysDepartment> children;


    @ManyToMany(middleTable = SysDepartmentRole.class, middleSelfField = "SysDepartmentId", middleTargetField = "SysRoleId")
    @TableField(exist = false)
    private List<SysRole> roles;

    @Serial
    private static final long serialVersionUID = 1L;

    @Data
    static class Parent {
        private String title;
    }
}